import { userInfoResult } from '@/types/user'

export const useUserInfo = () => {
  const permissionMap: Record<number, string> = {
    0: '校·管理员',
    1: '部·管理员',
    2: '教师',
  }
  /**
   * 计算用户身份权限
   */
  const getUserPermissions = (user: userInfoResult): string => {
    const baseRole = permissionMap[user.permissionLevel ?? -1] ?? ''
    if (user.isLeader === 1) {
      return baseRole + '（团队负责人）'
    }
    return baseRole
  }

  /**
   * 隐藏手机号码中间四位
   */
  const getMaskedPhone = (phone?: string): string => {
    if (!phone || phone.length < 7) return phone || ''
    return phone.slice(0, 3) + '****' + phone.slice(-4)
  }

  return {
    getUserPermissions,
    getMaskedPhone,
  }
}
